package webClient.UserInterfaceApplet;
import java.awt.*;
import java.awt.event.*;

import javax.swing.JCheckBox;

import UserInterfaceClasses.Login;



public class LoginApplet extends Dialog implements ActionListener {
 boolean id = false;
 Button ok,can;
 TextField username;
 TextField password;
 //Checkbox c = new Checkbox("Create NEW account", true);
 JCheckBox cb = 	new JCheckBox("Create NEW account");
 TextField confirmPassword;


 LoginApplet(Frame frame){
  super(frame, "Welcome", true);
  setLayout(new FlowLayout());
  //setLayout(new GridLayout(4, 2));
  username = new TextField(15);
  password = new TextField(15);
  password.setEchoChar('*');
  add(new Label("User :"));
  add(username);
  add(new Label("Password :"));
  add(password);
 
  handleCheckbox(cb);  
  
  addOKCancelPanel();
  createFrame();
  pack();
  setVisible(true);
  }
 
  void handleCheckbox(JCheckBox cb) {
	  add(cb);
	  
	  
	  /*if (cb.isSelected()){
		  add(new Label("Confirm Password :"));
		  add(confirmPassword);
		  cb.updateUI();
	  }
	  else { 
		  
	  }*/ 
	  
	  }

 void addOKCancelPanel() {
  Panel p = new Panel();
  p.setLayout(new FlowLayout());
  createButtons( p );
  add( p );
  }

 void createButtons(Panel p) {
  p.add(ok = new Button("OK"));
  ok.addActionListener(this); 
  p.add(can = new Button("Cancel"));
  can.addActionListener(this);
  }

 void createFrame() {
  Dimension d = getToolkit().getScreenSize();
  setLocation(d.width/4,d.height/3);
  }

 public void actionPerformed(ActionEvent ae){
	  if(ae.getSource() == ok) {
		  String username = this.username.getText();
		  String password = this.password.getText();
		  if(this.cb.isSelected()){
			  webClient.UserInterfaceClasses.Login.createAccount(username, password);
		  }else{
			  webClient.UserInterfaceClasses.Login.validateUser(username, password);
			  this.dispose();
		  }
	  }
	  else if(ae.getSource() == can) {
		  this.dispose();
	  }
  }
}
